package org.simple.wechat.demo.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.simple.wechat.demo.dto.Season;

import java.io.IOException;

/***
 * @author gaoqijin
 * @date 2020-11-18
 * @Description
 */
public class SeasonDeserializer extends JsonDeserializer<Season> {
    @Override
    public Season deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        String valueAsString = jsonParser.getValueAsString();
        for (Season value : Season.values()) {
            if(String.valueOf(value.getCode()).equals(valueAsString)){
                return value;
            }
        }
        return null;
    }
}
